# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1733
# Description:
# Author:       yzl
# Date:         2019-02-08
#-------------------------------------------------------------------------------

import threading;
from time import sleep,ctime

# 继承自线程类
# 之前存在写好的 线程函数
class Mythread(threading.Thread):
    # 线程函数 参数 线程名称
    def __init__(self,func,args,name=''):
        super().__init__(target=func,name=name,args=args)

    # def run(self):
    #     self._target(*self._args)

# 之前没有写好线程函数 不需要线程函数
class Mythread2(threading.Thread):
    def __init__(self,sec):
        super().__init__()
        self.sec = sec

    # 重写父类的 run 方法,里面的代码就是线程函数的代码
    def run(self):
        print(self.sec)
        sleep(self.sec)
        print('run method over')

def func(index,sec):
    print('开始执行',index,'执行时间',ctime())
    sleep(sec)
    print('执行结束', index, '结束时间', ctime())


def main():
    thread1 = Mythread(func,args=(40,4),name='thread1')
    thread1.start()

    thread2 = Mythread(func,args=(20,2),name='thread2')
    thread2.start()

    print('多线程准备就绪')

    thread1.join()
    thread2.join()

    thread3 = Mythread2(6)
    thread3.start()
    thread3.join()

    print('main is over')


if __name__ == '__main__':
    main()


